package netctoss.demo.mapper;

import netctoss.demo.entrty.Account;
import org.apache.ibatis.jdbc.SQL;
import org.springframework.util.StringUtils;

public class AccountProvider {

    public String selectPage(Account account){
        StringBuilder builder = new StringBuilder();
        builder.append("select * from netctoss.`account`");
        if (account != null){
            builder.append("where 1=1 ");
                if ( !StringUtils.isEmpty(account.getAccountIdcardNo())){
                    builder.append("and `account_idcard_no` like concat('%',#{accountIdcardNo},'%') ");
                }
                if (!StringUtils.isEmpty(account.getAccountRealName())){
                    builder.append(" and `account_real_name` like concat('%',#{accountRealName},'%') ");
                }
                if (!StringUtils.isEmpty(account.getAccountLoginName())){
                    builder.append("and `account_login_name` like concat('%',#{accountLoginName},'%') ");
                }
                if (!StringUtils.isEmpty(account.getAccountStatus())){
                    builder.append(" and `account_status` = #{accountStatus} ");
                }
            }
        return builder.toString();
//

        /*return new SQL(){{
            SELECT(" * ");
            FROM("account");
            if (account != null){
                if ( !StringUtils.isEmpty(account.getAccountIdcardNo())){
                    WHERE("`account_idcard_no` like concat('%',#{accountIdcardNo},'%')");
                }
                if (!StringUtils.isEmpty(account.getAccountRealName())){
                    WHERE("`account_real_name` like concat('%',#{accountRealName},'%')");
                }
                if (!StringUtils.isEmpty(account.getAccountLoginName())){
                    WHERE("`account_login_name` like concat('%',#{accountLoginName},'%')");
                }
                if (!StringUtils.isEmpty(account.getAccountStatus())){
                    WHERE("`account_status` = #{accountStatus}");
                }
            }

        }}.toString();*/
    }
}
